package com.acegear.horizon.domain.repository.jpa;

import com.acegear.horizon.domain.models.constraint.ClubEventState;
import com.acegear.horizon.domain.models.jpa.ClubEventBase;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;
import java.util.Optional;

/**
 * Created by mercury on 2016/12/22.
 */
public interface ClubEventBaseRepository extends PagingAndSortingRepository<ClubEventBase, Long>, JpaSpecificationExecutor<ClubEventBase> {
    Optional<ClubEventBase> findByClubEventId(Long clubEventId);

    @Query("select ceb from ClubEventBase ceb where ceb.clubEventId in ?1")
    List<ClubEventBase> findByClubEventIds(List<Long> clubEventIds);

    Integer countByOwnerId(Long ownerId);
    
    List<ClubEventBase> findByOwnerId(Long clubId, Pageable pageable);

    List<ClubEventBase> findByOwnerIdAndState(Long clubId, ClubEventState state, Pageable pageable);

    List<ClubEventBase> findByState(ClubEventState state, Pageable pageable);
}
